<template>
	<view class="news">
		<view class="lun">
			<swiper indicator-dots :circular="true" interval="3000" :autoplay="true">
				<swiper-item v-for="item in lun" :key="item.id" @click="tonewsdetail(item)">
					<image :src="'http://124.93.196.45:10001'+item.advImg"></image>
				</swiper-item>
			</swiper>
		</view>
		<u-tabs :list="type" @click="gettypenews"></u-tabs>
		<view class="news">
			<view class="n1" v-for="item in news" :key="item.id" @click="tonewsdetail(item)">
				<image :src="'http://124.93.196.45:10001'+item.cover"></image>
				<view class="n2">
					<text>{{item.title}}</text>
				</view>
				<view class="n3">
					<text>{{item.content}}</text>
				</view>
				<view class="n4">
					<text>评论：{{item.commentNum}}</text>
					<text>发布日期：{{item.publishDate}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lun:[],
				type:[],
				news:[]
			}
		},
		onLoad() {
			this.getlunbo()
			this.gettype()
			this.getallnews()
		},
		methods: {
			getlunbo(){
				this.api.get('/prod-api/api/rotation/list').then(res=>{
					this.lun=res.data.rows
				})
			},
			gettype(){
				this.api.get('/prod-api/press/category/list').then(res=>{
					this.type=res.data.data
				})
			},
			getallnews(){
				this.api.get('/prod-api/press/press/list').then(res=>{
					this.news=res.data.rows
				})
			},
			gettypenews(item){
				this.api.get('/prod-api/press/press/list?type='+item.id).then(res=>{
					this.news=res.data.rows
				})
			},
			tonewsdetail(item){
				uni.navigateTo({
					url:'/pages/newsdetail/newsdetail?id='+item.id
				})
			}
		}
	}
</script>

<style lang="scss">
.lun{
	image{
		width: 100%;
		height: 100%;
	}
}
.news{
	.n1{
		line-height: 30px;
		margin-top: 20px;
		image{
			width: 100%;
			height: 175px;
		}
	}
	.n2,.n3{
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	.n4{
		margin-top: 15px;
		display: flex;
		justify-content: space-between;
	}
}
</style>
